package com.example.design.shejimoshi.action.strategy.spring01;

import com.example.design.shejimoshi.action.strategy.spring01.dto.ExecutorDTO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class LinkExecutorHolder {

    @Resource
    private Map<String, LinkExecutor> linkExecutorMap;

    /**
     * 入参只有type，id
     *
     * @param linkExecutors
     */
    public Boolean execute(List<ExecutorDTO> linkExecutors) {
        List<ExecutorDTO> executorDTOS = new ArrayList<>();

        // 查询联动执行器
        linkExecutors.forEach(linkExecutor -> executorDTOS.add(linkExecutorMap.get(linkExecutor.getExecutorType()).getById(linkExecutor.getId())));

        /**
         * 执行器需要定义上层ExecutorDTO接口的原因，这里的执行器可能有各个类型的执行器
         * 所以需要各个执行器实现ExecutorDTO接口
         */
        // 执行联动执行器
        executorDTOS.forEach(executorDTO -> {
            Boolean result = linkExecutorMap.get(executorDTO.getExecutorType()).executor(executorDTO, "其他参数");
        });
        return true;
    }

}
